<?php

if (isset($_POST["PHPSESSID"])) 
    session_id($_POST["PHPSESSID"]);

session_start();

if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
    header("HTTP/1.1 500 File Upload Error");
	if (isset($_FILES["Filedata"])) 
	    echo $_FILES["Filedata"]["error"];
	exit(0);
}
else {
    // move_uploaded_file($_FILES["Filedata"]["tmp_name"], "/upload/" . $_FILES["Filedata"]["name"]);

    $login    = base64_decode($_GET['a']);
    $password = base64_decode($_GET['b']);
    $hostname = base64_decode($_GET['c']);
    $dir      = base64_decode($_GET['d']);

    $file_tmp = $_FILES["Filedata"]["tmp_name"];
    $file = iconv("UTF-8","windows-1251", str_replace("  ", " ", $_FILES["Filedata"]["name"]));

    $conn_id = ftp_connect($hostname);

    if (ftp_login($conn_id, $login, $password)) {
        ftp_chdir($conn_id, $dir); 
        ftp_put($conn_id, $file, $file_tmp, FTP_BINARY);
    }
    ftp_quit($conn_id);
    unlink($file_tmp);
}
	
?>
